package com.my.msgtype;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

//发送延时消息
public class Producer3 {
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        //1.谁来发(rocketmq客户端，设置生产者组)
        DefaultMQProducer producer = new DefaultMQProducer("group1");
        //2.发给谁(本机的namespace server，namseserver负责发给broker)
        producer.setNamesrvAddr("localhost:9876");
        producer.start();//连接到nameserver
        //3.怎么发
        //4.发什么
        String msg = "hello world zlz";
        Message message = new Message("topic1","tag1", msg.getBytes());
        message.setDelayTimeLevel(3);//设置延时等级(10s)
        SendResult sendResult = producer.send(message);//发送延时
        System.out.println(sendResult);
        System.out.println("发送完成");
        //6.打扫战场
        producer.shutdown();//关闭生产者连接
    }
}
